package com.baizhi.factory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class BeanFactory {
    private static Properties prop = new Properties();
    static {
        try {
            InputStream is = BeanFactory.class.getResourceAsStream("/aaa.properties");
            prop.load(is);
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static Object getBean(String key){
        Object obj = null;
        try {
            String value = prop.getProperty(key);
            obj = Class.forName(value).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return obj;
    }
}
